﻿namespace MicroCloud.Packs
{
    /// <summary>
    /// 系统核心模块
    /// </summary>
    [Description("系统核心模块")]
    public class CorePack : PackBase
    {
        /// <summary>
        /// 获取 模块级别
        /// </summary>
        public override PackLevel Level => PackLevel.Core;

        /// <summary>
        /// 将模块服务添加到依赖注入服务容器中
        /// </summary>
        /// <param name="services">依赖注入服务容器</param>
        /// <returns></returns>
        public override IServiceCollection AddServices(IServiceCollection services)
        {
            services.TryAddSingleton<IConfigureOptions<MicroCloudOptions>, MicroCloudOptionsSetup>();
            services.TryAddSingleton<ICancellationTokenProvider, NoneCancellationTokenProvider>();
            services.TryAddSingleton<StartupLogger>();

            services.TryAddScoped<IFilterService, FilterService>();
            services.TryAddScoped<IKeyValueStore, KeyValueStore>();

            services.TryAddTransient<IClientHttpCrypto, ClientHttpCrypto>();
            services.AddTransient<ClientHttpCryptoHandler>();

            services.AddDistributedMemoryCache();

            // 邮件服务
            services.TryAddSingleton<IEmailSender, MailKitSender>();
            services.TryAddSingleton<IEmailReceiver, MailKitReceiver>();
            services.AddHostedService<EmailReceiverHostedService>();

            //缓存特性
            services.TryAddSingleton<ICacheService, CacheService>();
            services.AddSingleton<ICacheDataService, CacheDataService>();
            services.AddMemoryCache();

            //初始化字体
            FontsHandler.Init();

            return services;
        }

    }

}
